# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=qownnotes
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=23.8.0
pkgrel=1
pkgdesc="Plain-text file markdown note taking with Nextcloud/ownCloud integration"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qownnotes.org/'
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-qt6-svg"
  "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
  "${MINGW_PACKAGE_PREFIX}-openssl"
  "${MINGW_PACKAGE_PREFIX}-qt6-websockets"
  "${MINGW_PACKAGE_PREFIX}-aspell"
  "${MINGW_PACKAGE_PREFIX}-qt6-5compat"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("https://github.com/pbek/QOwnNotes/releases/download/v${pkgver}/qownnotes-${pkgver}.tar.xz")
sha256sums=('66f64e51c2ad63e574ce1aac398362dd6f32c513d4758b29da44871134424cbb')

build() {
  cd "${_realname}-${pkgver}"

  qmake6 \
    QMAKE_CFLAGS_RELEASE="${CFLAGS}" \
    QMAKE_CXXFLAGS_RELEASE="${CXXFLAGS}" \
    QMAKE_LFLAGS_RELEASE="${LDFLAGS}"
  make
}

package() {
  cd "${_realname}-${pkgver}"

  # install application
  install -D -m755 release/QOwnNotes.exe "${pkgdir}${MINGW_PREFIX}/bin/QOwnNotes.exe"

  # install visuals
  install -D -m644 PBE.QOwnNotes.desktop "${pkgdir}${MINGW_PREFIX}/share/applications/PBE.QOwnNotes.desktop"
  for format in {16x16,24x24,32x32,48x48,64x64,96x96,128x128,256x256,512x512}; do
    install -D -m644 "images/icons/${format}/apps/QOwnNotes.png" "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/$format/apps/QOwnNotes.png"
  done
  install -D -m644 "images/icons/scalable/apps/QOwnNotes.svg" "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/scalable/apps/QOwnNotes.svg"

  # install languages (it looks for "qt5" even in the qt6 build)
  install -d "${pkgdir}${MINGW_PREFIX}/share/qt5/translations/"
  install -D -m644 languages/*.qm "${pkgdir}${MINGW_PREFIX}/share/qt5/translations/"
}
